//
//  RootView.m
//  Jiexi
//
//  Created by lanou3g on 15-4-9.
//  Copyright (c) 2015年 ncy. All rights reserved.
//

#import "RootView.h"
@implementation RootView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self p_setupView];
    }
    return self;
}

- (void)p_setupView
{
    self.backgroundColor = [UIColor yellowColor];
    //准备数据
    
    NSMutableArray *tempArray = [NSMutableArray array];
    //将image循环加入数组
    for (int i = 1; i < 9; i++) {
        UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"%d.tiff",i]];
        
        [tempArray addObject:img];
    }
    
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 300, 50, 50)];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    button.backgroundColor = [UIColor blueColor];
    [self addSubview:button];
    
    UIButton *button1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 400, 50, 50)];
    [button1 addTarget:self action:@selector(stopAction:) forControlEvents:(UIControlEventTouchUpInside)];
    button1.backgroundColor = [UIColor blueColor];
    [self addSubview:button1];
    
    
    self.backgroundColor = [UIColor grayColor];
    self.imv = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    self.imv.backgroundColor = [UIColor yellowColor];
    //设置动态图片的数组
    self.imv.animationImages = tempArray;
    //每张图片持续时间
    self.imv.animationDuration = 0.4;
    //设置循环次数,(0 为无限循环)
    self.imv.animationRepeatCount = 0;
    
    //[self.imv startAnimating];
    
    [self addSubview:self.imv];

}
- (void)buttonAction:(UIButton *)sender
{
    
    [self.imv startAnimating];
}
- (void)stopAction:(UIButton *)sender
{
    [self.imv stopAnimating];
}

@end
